package main

import (
	"fmt"
)

type A struct {
	Name string
	age int
}

type B struct {
	A  // 继承结构体A中字段，无论大小写
}

type C struct {
	B
}

type D struct {
	A
	B
}

type E struct {
	Name string
	Gender string
}

type F struct {
	A
	E
}

type F2 struct {
	*A
	*E
}

type G struct {
	a A  // 有名结构体
}

func main() {
	a := &A{Name: "小花a", age: 12}
	fmt.Println(*a)

	//b := &B{Name:"小花", age:12}  // 次方式不可行
	var b B
	b.Name = "小花b"  // 实际 b.A.Name = "小花"
	b.A.age = 12
	fmt.Println(b)
	fmt.Println(b.Name)

	var c C
	c.Name = "小花c"
	fmt.Println(c)
	fmt.Println(c.Name)

	var d D
	d.Name = "小花d"
	d.B.age = 13  // 先继承A
	d.A.age = 12
	fmt.Println(d)
	fmt.Println(d.age)

	var f F
	//f.Name = "小花f"  // A和F结构体中都有字段Name，因此必须通过指定匿名结构体名类区分
	f.A.Name = "小花f"
	f.E.Name = "小花E"
	fmt.Println("f: ", f)

	// 多个结构体实例
	f1 := F{A{"小花Af1", 12}, E{"小花Ef1", "女"}}
	fmt.Println(f1)
	f2 := F{
		A{
			Name: "小花Af2",
			age: 12,
		},
		E{
			Name: "小花Ef2",
			Gender: "女",
		},
	}
	fmt.Println(f2)

	f3 := F2{
		&A{"小花Af3", 12},
		&E{"小花Ef3", "女"},
	}
	fmt.Println(*f3.A, *f3.E)
	f4 := F2{
		&A{
			Name: "小花Af3",
			age: 12,
		},
		&E{
			Name: "小花Ef3",
			Gender: "女",
		},
	}
	fmt.Println(*f4.A, *f4.E)


	var g G
	g.a.Name = "小花g"
	fmt.Println(g)

}
